package xuhaijia.lanou3g.autohome.activity;
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                   \\`.
//        .'//            为什么坚持  想一想当初             \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-.  \\`.
//    .'//.-"                 `-.  |  .-'                 "-. \\`.
//  .'//______.============-..   \ | /   ..-============._______\\`.
//.'//____________________________\|/_____________________________\\`.
// 
//                             

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;

import xuhaijia.lanou3g.autohome.R;
import xuhaijia.lanou3g.autohome.base.BaseActivity;

/**
 * Created by 7 on 16/8/27.
 */
public class WebViewActivity extends BaseActivity implements View.OnClickListener {
    private Intent intent;
    private WebView webView;
    private TextView closeTv;
    private TextView titleTv;
    private ProgressBar pb;


    @Override
    protected int setLayout() {
        return R.layout.activity_webview;
    }

    @Override
    protected void initView() {
        intent = getIntent();
        webView = bindView(R.id.activity_webview_wv);
        closeTv = bindView(R.id.activity_webview_close);
        closeTv.setOnClickListener(this);
        titleTv = bindView(R.id.activity_webview_title);
        pb = bindView(R.id.activity_webview_pb);
        pb.setVisibility(View.VISIBLE);
    }

    @Override
    protected void initData() {
        String url = intent.getStringExtra("url");
        webView.setWebViewClient(new WebViewClient());
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        WebChromeClient webChromeClient = new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                titleTv.setText(title);
            }

            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                pb.setProgress(newProgress);
                if (newProgress == 100) {
                    pb.setVisibility(View.GONE);
                }

            }
        };
        webView.setWebChromeClient(webChromeClient);
        webView.loadUrl(url);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.activity_webview_close:
                finish();
                break;
        }
    }
}
